<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<!-- header -->
		<%@ include file="/WEB-INF/views/include/header.jsp"%>
		<style>
			a{
				text-decoration: none;
				color: #ffffff;
			}
			a:target{
				color:black;
			}

		</style>
	</head>
	<body class="no-skin">
		<!-- /section:basics/navbar.layout -->
		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<!-- /section:basics/sidebar -->
			<div class="main-content">
				<div class="main-content-inner">
					<div class="page-content">
						<!-- /section:settings.box -->
						<div class="row">
							<div class="col-xs-8">
								<div class="pull-left">
									    
										<button class="btn btn-sm btn-info" id="query">条件搜索</button>
									<%-- <shiro:hasPermission name="modules:sys:huashu:query"></shiro:hasPermission> --%>
									
										<button class="btn btn-sm btn-default" id="edit" >项目修改</button>
<%-- 									<shiro:hasPermission name="modules:sys:huashu:edit"></shiro:hasPermission>
 --%>									
										<button class="btn btn-sm btn-success" id="create" style="display: none">项目录入</button>
<%-- 									<shiro:hasPermission name="modules:sys:huashu:create"></shiro:hasPermission>
 --%>									<!-- <button class="btn btn-sm btn-success" id="createCla">新增分类</button> -->
										<button class="btn btn-sm btn-danger" id="delete" >删除项目</button>

									   <button class="btn btn-sm btn-danger" id="export" >导出意向表</button>

									   <button class="btn btn-sm btn-danger" id="exportSummary" >导出一览表</button>
                                      <%-- <button class="btn btn-sm btn-danger" id="report" >报表</button>--%>
									<%--<a class="btn btn-sm btn-danger" id="export" href="/export/summaryExport" > 导出</a>--%>
									<%--<shiro:hasPermission name="modules:sys:dept:excel">
										<button class="btn btn-sm btn-pink" id="export">导出</button>
									</shiro:hasPermission>--%>
								</div>
							</div>
							<div class="col-xs-4" style="text-align: left">
								<div class="btn-success" style="padding: 5px 10px;display: inline-block">实际项目数：<span class="actual-count" style="font-size: 20px"></span>个</div>
								<div class="btn-success" style="padding: 5px 10px;display: inline-block;margin-left: 5px;">实际投资总额：<span class="actual-price" style="font-size: 20px"></span>亿</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
									<!-- jqGrid表格 -->
									<table id="gridTable"></table>
									<!-- jqGrid工具类 -->
									<div id="gridPager"></div>
									<!-- 查询对话框 -->
									<div style="display: none;">
										<div class="row" id="queryDialog"></div>
									</div>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->

			<%--<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
			</a>--%>
			
			<!-- dialog -->
			<%@ include file="/WEB-INF/views/include/dialog.jsp"%>
		</div><!-- /.main-container -->
	</div>	
		<!-- footer -->
		<%@ include file="/WEB-INF/views/include/footer.jsp"%>
		
		<script type="text/javascript">
			//基本路径
			var baseUrl = "<s:url value="/modules/sys/find"></s:url>/"
			
			//jqgrid的表格高度
			var height = 320;
			//jqgrid表格行头的中文
			var colNames = ['申报单号','小分队','项目名称','投资方名称','项目内容和规模 ','项目进展情况','合计金额',
				'项目类别','项目阶段','年份','更新日期','佐证材料', '审核状态', '实际个数','实际金额','市考评日期'];
			//jqgrid表格中每一行的信息模型
			var colModel = [
				{name:'sysId', index:'sysId',width:160,editable: false,key:true},
				{name:'teamName',index:'teamName', width:160,editable: true},
				{name:'projectName',index:'projectName', width:220, editable: true},
				{name:'investorName',index:'investorName', width:220, editable: true},
				{name:'projectContent',index:'projectContent', width:200, editable: true},
				{name:'projectProgress',index:'projectProgress', width:200, editable: true},
				{name:'totalInver',index:'totalInver', width:60, editable: true,formatter:'number'},
				{name:'projectClass',index:'projectClass', width:100,editable: true},
				{name:'projectStage',index:'projectStage', width:80, editable: true},
				{name:'datatime',index:'datatime', width:50,editable: true},
				{name:'updDate',index:'updDate',width:100,editabel:false},
				{name:'taxproof',index:'taxproof', width:200, editable: true,formatter:showbtnFmatter,edittype:'custom'},
				{name:'isaudit',index:'isaudit', width:80,editable: false,formatter:aa10Fmatter},
				{name:'realNum',index:'realNum', width:80, editable: true},
				{name:'realInver',index:'realInver', width:80, editable: true},
				{name:'cityEvaluation',index:'cityEvaluation',width:100,editable:true},

			];
			
			//jqgrid的具体执行方法
			jqgrid({
				shrinkToFit:false,
				gridTableId : "#gridTable",
				gridPagerId : "#gridPager",
				footerrow:true,
                userDataOnFooter:true,
                gridComplete:function () {
					var sumtotal =$("#gridTable").getCol('totalInver',false,'sum');
					var realnumsum=$("#gridTable").getCol('realNum',false,'sum');
					var realInvest=$("#gridTable").getCol('realInver',false,'sum');
					//console.log(sumtotal);
                    $("#gridTable").footerData('set',{'totalInver':sumtotal,'realNum':realnumsum,'realInver':realInvest});
                },

            });

			/*var sumVal = $("#gridTable").getCol('totalInver',false,'sum');
			console.log(sumVal+"ssssssssss");
			$("#gridTable").footerData('set','totalInver',sumVal);*/
			
			function aa10Fmatter(cellvalue,options,rowObject)
			{
				if(cellvalue=="1"){
					return "审核通过";
				}else if(cellvalue=="0") {
					return "未审核";
				}else if(cellvalue=="2"){
					return "作废";
				}else if(cellvalue=="3"){
					return "回退";
				}
			}
			//进度更新按钮
            function showdebriFmatter(cellvalue,options,rowObject)
            {
                if(cellvalue==null||cellvalue==""){
                    return "无进度更新";
                }else{


                    var imgeHtml =" <button class=\"col-sm-12 btn btn-large btn-primary\"  onclick='btnlarge()'>已更新请查看</button> ";
                    //<a href="javascript:parent.openapp('/modules/sys/Debriefing','debirefing','进度登记')" >
                    return imgeHtml;

                }
            }

			//添加下载按钮
			function showbtnFmatter(cellvalue,options,rowObject)
			{
				if(cellvalue==null||cellvalue==""){
					return "无上传材料";
				}else{
					
					 
				var imgeHtml =" <button class=\"col-sm-5 btn btn-large btn-primary\"   onclick=\" downDetail('"+cellvalue+"'); \"   >下载</button> ";  
				return imgeHtml;
			  
				}
			}
			//下载按钮
			function downDetail(id){
				//alert(id);
				   var url ="/pictureUpload/download/"+id+".zip";
					window.open(url);
			}
			
			//加载查询对话框
			$("#queryDialog").load(getUrl("filter"));
			
			//重置表单
			function reset() {
				resetForm("#formDialog form");
			}
			
			//显示查询对话框
			var queryDialog = $("#queryDialog");
			$("#query").click(function() {
				showDialog({
					dialogTitle: '查询对话框',
					dialogBody: queryDialog,
					dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
					"<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
					"<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
				});
			});
			var exportData = '';
			var exportDataArray='';
			//具体查询方法
			function query() {
                //exportData = $('#formDialog form').serializeObject();
                exportData     =$('#formDialog form').serialize();
                console.log(exportData);
				exportDataArray=$('#formDialog form').serializeArray();
                //console.log(exportData);
				seachJqgird("#gridTable","#formDialog form");
				$("#formDialog").modal('hide');
                var  newObj={};
                exportDataArray.forEach(function (val,index) {

                    newObj[val.name]=val.value
            })
				console.log(newObj);
                $.ajax({
                    url :'/modules/sys/find/realNumAndInver' ,
                    dataType : "json", //返回数据形式为json
                    type : "POST",
                    contentType : 'application/json;charset=UTF-8',
                    data : JSON.stringify(newObj),
                    success : function(data) {
                        console.log(data);
                        var count=data.data.num.toFixed(2);
                        var price=data.data.sum1.toFixed(2)
                        $('.actual-count').text(count);
                        $('.actual-price').text(price);
                    }
                });
			}

			//导出按钮(意向表）
			$("#export").click(function () {
               // exportData=decodeURIComponent(exportData,true);//解码
                var url ="/export/ExportYixiang"+'?'+exportData;
               // console.log(exportData);
               // console.log(exportDataArray);
				//var jsonexport =JSON.stringify(exportDataArray);
				console.log(exportDataArray);
				//console.log(exportDataArray[10].value);
				if(exportDataArray==""){
                    $(".shade").fadeIn(100);
                    $(".warning").fadeIn(100);
                    showShade();
                    //警告框自定义内容
                    $('.la-square-jelly-box').hide();
                    $('.warning>.cont').html('请先查询意向项目在导出');
                    return;
				}
               	if(exportDataArray[10].value!="意向项目")
				{
				   // alert("请先查询意向项目在导出");
                    $(".shade").fadeIn(100);
                    $(".warning").fadeIn(100);
                    showShade();
                    //警告框自定义内容
                    $('.la-square-jelly-box').hide();
                    $('.warning>.cont').html('请先查询意向项目在导出');
				    return;
				}
				window.open(url);

            });
			//一览表导出
            $("#exportSummary").click(function () {
                // exportData=decodeURIComponent(exportData,true);//解码
                var url ="/export/ExportSummary"+'?'+exportData;
                console.log(exportData);
                window.open(url);

            });
			/*$("#report").click(function () {
               var url ="/export/reportExport";
               window.open(url);
            });*/
			/*function exportExvel() {
				query();
            }*/
			
			//更新操作
			$("#edit").click(function() {
				showEditView();
			});
			
			//执行更新操作
			function edit() {
				executeSaveOrUpdate({
					formId: "#formDialog form",
					dialogId: "#formDialog",
					url: getUrl("edit"),
					tableId: "#gridTable",
					successMessage: "更新成功",
					successTitle: '更新对话框',
					failMessage: '更新失败',
					failTitle: '消息对话框'
				});
			}
			
			//显示编辑对话框
			function showEditView() {
				showEditDialog({
					tableId: "#gridTable",
					dialogTitle: "更新对话框",
					dialogUrl: getUrl("edit"),
					dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn">更新</button>' + 
					'<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' + 
					'<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
					errorTitle: "消息对话框",
					errorMutiSelectMessage: '您当前选中多行，请重新选择',
					errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
					errorOk: '确定'
				});
			}	
			
			//显示编辑对话框
			function showView() {
				showEditDialog({
					tableId: "#gridTable",
					dialogTitle: "更新对话框",
					dialogUrl: getUrl("edit"),

					errorTitle: "消息对话框",
					errorMutiSelectMessage: '您当前选中多行，请重新选择',
					errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
					errorOk: '确定'
				});
			}	
			
			//删除
			$("#delete").click(function() {
				showDeleteView();
			});
			
			//显示删除对话框
			function showDeleteView() {
				showDeleteDialog({
					url: getUrl("delete"),
					tableId: "#gridTable",
					confirmTitle: "确认对话框",
					confirmMessage: "是否确定删除?",
					confirmOk: "确定",
					confirmCancel: "取消",
					successMessage: "删除成功",
					successTitle: "消息对话框",
					failMessage: "删除失败",
					failTitle: "消息对话框",
					errorTitle: "警告提示框",
					errorMessage: "您当前尚未选中一行，请选择后再试",
					errorOk: "确定"
				});
			}
			
			//显示创建对话框
			$("#create").click(function(){
				loadDialog({
					dialogTitle: '创建对话框',
					dialogUrl: getUrl("create"),
					dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">提交审核</button>' + 
					'<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' + 
					'<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
				});
			});
			
			//分类编辑框
			$("#createCla").click(function(){
				loadDialog({
					dialogTitle: '创建对话框',
					dialogUrl: getUrl("createCla"),
					dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' + 
					'<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' + 
					'<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
				});
			});
			//保存数据
			function create() {
				executeSaveOrUpdate({
					formId: "#formDialog form",
					dialogId: "#formDialog",
					url: getUrl("create"),
					tableId: "#gridTable",
					successMessage: "保存成功",
					successTitle: '保存对话框',
					failMessage: '保存失败',
					failTitle: '消息对话框'
				});
			}
			
			
			$("#gridTable").dblclick(function(e){
				showView();
			});

			function aa11Fmatter(cellvalue,options,rowObject)
			{
				if(cellvalue=="0"){
					return "否";
				}else if(cellvalue=="1") {
					return "是";
				}else {
					return "";
				}
			}

			function showBanFmatter(cellvalue,options,rowObject)
			{
				if(cellvalue=="0"){
					return "";
				}else {
					console.log(cellvalue);
					return cellvalue;
				}
			}

            // 警告框
			$(function () {
                function showShade(){
                    var $vW = $(window).width();
                    var $w = $(".warning").outerWidth();
                    var $vH = $(window).height();
                    var $h = $(".warning").outerHeight();
                    $(".warning").css({"left":($vW - $w)/2 + "px","top":($vH - $h)/3 + "px"});
                };
                //警告框
                $(function(){
                    //浏览器大小发生改变
                    $(window).resize(function(){
                        showShade();
                    });
                    //点击span关闭
//                     $("span").bind("click",function(){
//                         $(".shade").fadeOut(100);
//                         $(".warning").fadeOut(100);
//                     });
//                     //绑定键盘事件  按下esc键退出
//                     $(document).keyup(function(ev){
// //                alert(ev.keyCode);  获取esc的键码27
//                         if(ev.keyCode == 27){
// //                    $("span").click();
//                             //模拟事件
//                             $("span").trigger("click");
//                         }
//                     })
//                     $('.shade').click(function () {
//                         $("span").trigger("click");
//                     })
                });
                $.ajax({
                    url :'/modules/sys/find/realNumAndInver' ,
                    dataType : "json", //返回数据形式为json
                    type : "POST",
                    contentType : 'application/json;charset=UTF-8',
                    data : JSON.stringify({datetime:''}),
                    success : function(data) {
                        console.log(data);
                        var count=data.data.num.toFixed(2);
                        var price=data.data.sum1.toFixed(2)
                        $('.actual-count').text(count);
                        $('.actual-price').text(price);
                    }
                });
            })
			function btnlarge() {
                parent.openapp('/modules/sys/Debriefing','debirefing','进度登记')
            }

		</script>
		
	</body>
</html>